// ---------------------------------------------------------------------
//
// -- 省略号动画
// -- author £
//
// ---------------------------------------------------------------------

cc.Class({
    extends: cc.Component,

    properties: {
        duration: {
            default: 1,
            tooltip: '动画间隔'
        },
    },

    ctor: function () {
        this._scheduler = new (require('common').MyScheduler)();
        this._itr = -1;
        this.dots = [];
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        let len = this.node.children.length;

        for (let i = 0; i < len; ++i) {
            this.dots[i] = this.node.children[i];
        }

        this._clearDots();
    },

    start () {
        // this.play();
    },

    play: function () {
        this._scheduler.schedule(this._playNext, 
            this.duration, cc.macro.REPEAT_FOREVER, 0, this, 'animate');
    },

    stop: function () {
        this._itr = -1;
        this._scheduler.unscheduleAllCallbacks();
        this._clearDots();
    },

    _playNext: function () {
        if (this._itr === 2)
            this._clearDots();

        ++ this._itr;
        
        if (this._itr === 3)
            this._itr = 0;

        this.dots[this._itr].active = true;
    },

    _clearDots: function () {
        let len = this.dots.length;

        for (let i = 0; i < len; ++i) {
            this.dots[i].active = false;
        }
    },

    // update (dt) {},
});
